/**
 * @author zhangyifan
 */

import java.util.Scanner;

public class ShapeAreaCalculator {
    private static final String SQUARE = "正⽅形";
    private static final String CIRCLE = "圆形";
    private static final String TRIANGLE = "三⻆形";
    private static final String TRAPEZOID = "梯形";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 用户选择形状
        System.out.println("请输入形状名称（正方形、圆形、三角形 或 梯形）：");
        String shape = scanner.nextLine().trim().toLowerCase();

        // 根据用户选择调用相应的方法
        if (SQUARE .equals(shape)) {
            calculateSquareArea(scanner);
        } else if (CIRCLE.equals(shape)) {
            calculateCircleArea(scanner);
        } else if (TRIANGLE .equals(shape)) {
            calculateTriangleArea(scanner);
        } else if (TRAPEZOID.equals(shape)) {
            calculateTrapezoidArea(scanner);
        } else {
            System.out.println("不支持的形状类型。");
        }

        scanner.close();
    }
    /**
     * 计算正⽅形⾯积的⽅法
     * @param scanner ⽤于接收⽤户输⼊的Scanner对象
     */
    public static void calculateSquareArea(Scanner scanner) {
        System.out.println("请输入正方形的边长：");
        double side = scanner.nextDouble();
        System.out.println("正方形的面积是：" + squareArea(side));
    }

    /**
     * 计算圆形⾯积的⽅法
     * @param scanner ⽤于接收⽤户输⼊的Scanner对象
     */

    public static void calculateCircleArea(Scanner scanner) {
        System.out.println("请输入圆形的半径：");
        double radius = scanner.nextDouble();
        System.out.println("圆形的面积是：" + circleArea(radius));
    }

    /**
     * 计算三⻆形⾯积的⽅法
     * @param scanner ⽤于接收⽤户输⼊的Scanner对象
     */
    public static void calculateTriangleArea(Scanner scanner) {
        System.out.println("请输入三角形的三条边长：");
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();
        System.out.println("三角形的面积是：" + triangleArea(a, b, c));
    }

    /**
     * 计算梯形⾯积的⽅法
     * @param scanner ⽤于接收⽤户输⼊的Scanner对象
     */

    public static void calculateTrapezoidArea(Scanner scanner) {
        System.out.println("请输入梯形的上底长度：");
        double base1 = scanner.nextDouble();
        System.out.println("请输入梯形的下底长度：");
        double base2 = scanner.nextDouble();
        System.out.println("请输入梯形的高：");
        double height = scanner.nextDouble();
        System.out.println("梯形的面积是：" + trapezoidArea(base1, base2, height));
    }

    /**
     * 计算正⽅形⾯积的静态⽅法
     * @param side 正⽅形的边⻓
     * @return 返回正⽅形的⾯积
     */

    public static double squareArea(double side) {
        return side * side;
    }

    /**
     * 计算圆形⾯积的静态⽅法
     * @param radius 圆形的半径
     * @return 返回圆形的⾯积
     */
    public static double circleArea(double radius) {
        return Math.PI * radius * radius;
    }
    /**
     * 计算三⻆形⾯积的静态⽅法（使⽤海伦公式）
     * @param a 三⻆形的第⼀条边⻓
     * @param b 三⻆形的第⼆条边⻓
     * @param c 三⻆形的第三条边⻓
     * @return 返回三⻆形的⾯积
     */
    public static double triangleArea(double a, double b, double c) {
        double s = (a + b + c) / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
    }

    /**
     * 计算梯形⾯积的静态⽅法
     * @param base1 梯形的上底⻓度
     * @param base2 梯形的下底⻓度
     * @param height 梯形的⾼
     * @return 返回梯形的⾯积
     */
    public static double trapezoidArea(double base1, double base2, double height) {
        return (base1 + base2) * height / 2;
    }
}
